const fs = require("fs");
const path = require("path");

function readDir(p) {
  const dirPath = path.join(__dirname, p);
  const list = fs.readdirSync(dirPath);
  list.forEach((k) => {
    const filePath = path.join(dirPath, k);
    const s = fs.statSync(filePath);
    if (s.isFile()) {
      renameFile(filePath, dirPath, k);
    }
  });
}
const reg = /《(.*?)》/;
function renameFile(filePath, dirPath, k) {
  if (reg.test(k)) {
    const l = reg.exec(k);
    const ext = path.extname(filePath);
    fs.renameSync(filePath, path.join(dirPath, l[1] + ext));
  }
}

readDir("./");
